package com.yfyszk.kingbird.common.result;


import com.yfyszk.kingbird.common.exception.ResultEnum;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 类名称：ApiPageResult
 * 类描述：ApiPageResult 后台管理系统分页返回结果类
 * 创建人：wgc
 * 创建时间：2018年03月30日 下午10:04:07
 */
@Slf4j
public final class ApiPageResult<T extends Serializable> implements Serializable {

    //private static final Logger logger = LoggerFactory.getLogger(ApiPageResult.class);

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code = ResultEnum.ERROR.getCode();

    /**
     * 错误信息
     */
    private String msg = null;

    /**
     * 返回结果实体
     */
    private Object data = null;

    /**
     * 返回结果实体
     */
    private Integer total = 0;
    /**
     * 返回其他结果实体
     */
    private Object dataother = null;

    public ApiPageResult() {
    }


    public ApiPageResult(int code, String msg, Object data, Integer total) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }

    public ApiPageResult(int code, String msg, Object data, Integer total, Object dataother) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
        this.dataother = dataother;
    }


    //返回数据和总条数
    public static <T extends Serializable> ApiPageResult<T> success(Object data, Integer total) {
        log.debug("返回信息：data={}, total={}", data, total);
        return new ApiPageResult<T>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data, total);
    }

    public static <T extends Serializable> ApiPageResult<T> success(Object data, Integer total, Object rowsOthers) {
        log.debug("返回信息：data={}, total={},rowsOthers{}", data, total, rowsOthers);
        return new ApiPageResult<T>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data, total, rowsOthers);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Object getDataother() {
        return dataother;
    }

    public void setDataother(Object dataother) {
        this.dataother = dataother;
    }

    @Override
    public String toString() {
        return "ApiPageResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", total=" + total +
                ", dataother=" + dataother +
                '}';
    }

}
